package bjut.zrpc.core.optimization.netty;

import bjut.zrpc.core.optimization.bean.ZRpcServiceBean;
import bjut.zrpc.core.optimization.proctol.MessageDecoder;
import bjut.zrpc.core.optimization.proctol.MessageEncoder;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.DefaultEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
/**
 * @Author: zhuzhiming
 * @Date: 2022/6/23 23:58
 */
public class NettyServerInitializer extends ChannelInitializer<SocketChannel> {

    private final DefaultEventLoopGroup defaultEventLoopGroup;

    public NettyServerInitializer(DefaultEventLoopGroup defaultEventLoopGroup) {
        this.defaultEventLoopGroup = defaultEventLoopGroup;
    }

    @Override
    protected void initChannel(SocketChannel socketChannel) throws Exception {

        socketChannel.pipeline()
                //.addLast(new IdleStateHandler(60, 0, 0, TimeUnit.SECONDS))
                .addLast(new MessageEncoder())
                .addLast(new MessageDecoder())
                .addLast(defaultEventLoopGroup, new NettyServerHandler());

    }
}
